package com.coszero.common.dialog.loading;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.coszero.commonlib.R;
import com.coszero.utils.device.NavigationBarUtils;

/**
 * Desc： 网络加载进度弹窗
 *
 * @author xmqian
 * Email:xmqian93@163.com
 * Date: 2020/7/10 17:19
 * @version 1
 */
public class LoadingProgressView extends Dialog {

    public LoadingProgressView(Context context) {
        this(context, R.style.com_lodingDialog);
    }

    public LoadingProgressView(Context context, int theme) {
        super(context, theme);
//        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if (window != null) {
            NavigationBarUtils.hideNavigationBar(window, getContext());
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
        setCancelable(false);
        setContentView(R.layout.com_dialog_loading_progress);
    }

    @Override
    public void show() {
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

        super.show();

        fullScreenImmersive(getWindow().getDecorView());

        this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    }

    private void fullScreenImmersive(View view) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

            int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE

                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_FULLSCREEN;

            view.setSystemUiVisibility(uiOptions);

        }

    }
}